package chainListPractise;

public class ChainList {
    //定义节点
    static class Node{
        public int val;
        public Node next;
        public Node(int val) {
            this.val = val;
        }
    }
    public Node head;

    //尾插
    public void add(int val) {
        //创建一个节点
        Node node = new Node(val);
        if(this.head==null) {
            this.head = node;
        } else {
            Node cur = this.head;
            while(cur.next!=null) {
                cur = cur.next;
            }
            cur.next = node;
        }
    }
}

class Test{
    public static void main(String[] args) {
        ChainList test = new ChainList();
        test.add(1);
        test.add(2);
        test.add(3);
        while(test.head!=null) {
            System.out.println(test.head.val);
            test.head = test.head.next;
        }
    }
}